package com.utils;

import java.sql.*;

public class DBUtil {


    private DBUtil() {

    }

    private static final String url = "jdbc:mysql://localhost:3306/pay_library?useUnicode=true&characterEncoding=UTF-8&serverTimezone=PRC";
    private static final String userName = "root";
    private static final String password = "20000717";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConn() throws SQLException {
        Connection conn = null;
        conn = DriverManager.getConnection(url,userName,password);
        return conn;
    }

    public static void freeConn(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }

    public static void freeStatement(Statement pstm) throws SQLException {
        if (pstm != null) {
            pstm.close();
        }

    }

    public static void freeResultSet(ResultSet rs) throws SQLException {
        if (rs != null) {
            rs.close();
        }
    }
}
